<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="java.util.*"%>
<html>
<%
    Map sessionSet = (Map) session.getServletContext().getAttribute("sessions");
%>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>bomc系统首页</title>
    <jsp:include page="/common/link.jsp"></jsp:include>
    <link rel="stylesheet" type="text/css"
          href="<%=application.getContextPath()%>/njs/basd/easyui/jquery-easyui-1.3.3/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css"
          href="<%=application.getContextPath()%>/njs/basd/easyui/jquery-easyui-1.3.3/themes/icon.css" />
    <script type="text/javascript"
            src="<%=application.getContextPath()%>/njs/basd/easyui/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <link rel="stylesheet" type="text/css"
          href="<%=application.getContextPath()%>/nresources/basd/itsm/jquery.hiAlerts.css" />
    <script type="text/javascript"
            src="<%=application.getContextPath()%>/njs/basd/hiAlerts/jquery.hiAlerts-min.js"></script>
    <link rel="stylesheet" type="text/css"
          href="<%=application.getContextPath()%>/nresources/basd/itsm/itilManage.css" />
    <script type="text/javascript"
            src="<%=application.getContextPath()%>/njs/basd/jcarousellite_1.0.1.pack.js"></script>
    <jsp:include page="/WEB-INF/ibnms/common/ztree.jsp"></jsp:include>
</head>

<body>
<div class="header clearfix">
    <div class="left-panel fl clearfix">
        <a class="logo" href="#"><img src="<%=application.getContextPath()%>/nresources/ued/images/logo.jpg" /></a>
    </div>
    <div class="right-panel clearfix">
        <div class="right-panel-t">
            <div class="fl"><p class="logoTitle"><a href="#"><s:property value="filter.PROJECT_NAME" /></a></p></div>
            <div class="fr">
                <ul class="blue-link">
                    <li>
                        <a system_id='mainpage' class="on" href="#">首页</a>
                    </li>
                    <s:iterator value="subSystemList" var="subSystems" status="st">
                        <li system_id='<s:property value="#subSystems.MODULE_ID"/>' >
                            <a system_id='<s:property value="#subSystems.MODULE_ID"/>' system_path='<s:property value="#subSystems.MODULE_PATH"/>'  system_name='<s:property value="#subSystems.MODULE_NAME"/>'
                               href="#" module_target='<s:property value="#subSystems.MODULE_TARGET"/>'><s:property value="#subSystems.MODULE_NAME" /> </a>
                        </li>
                    </s:iterator>
                </ul>
            </div>
            <div class="clear"></div>
        </div>
        <div class="right-panel-b">
            <div id="time" class="actualTime" style="display:none"></div>
            <div id="shotCutList" class="fr" style="float:left;">
                <div class="move-right" style="float:right;">
                    <a style="cursor: pointer"><img src="nresources/ued/images/right.png" style="margin-top:4px"/></a>
                </div>
                <div class="move-left" style="float:left;">
                    <a style="cursor: pointer"><img src="nresources/ued/images/left.png" style="margin-top:4px"/></a>
                </div>
            </div>
            <div class="fr">
                <div class="end">
                    <div class="end"><a href="#" style="height:20px" id="account">我的账户</a></div>
                    <div class="end"><a href="#" id="shortmenuBtn">快捷菜单</a></div>
                    <div id="shortmenuShow" class="easyui-menu" style="width: 100px;">
                    </div>
                </div>
                <div class="end"><a href="#" style="cursor:text"><s:property value="currentUser.NAME" /></a></div>
                <div class="end"><a href="#" style="cursor:text">当前在线人数：<%=sessionSet.size()%>人</a></div>
            </div>
            <div class="clear"></div>
        </div>
    </div>
</div>
<div class="container container-2">
    <div id="layout">
        <div position="center" class="main-panel">
            <div class="tabspage">
                <span class="scrollPrev tabspage-pre"></span>
                <span class="scrollNext tabspage-next"></span>
                <div title="首页" tabid="indexpage" lselected="true">
                    <iframe class="framepage mgt-5" src="<%=application.getContextPath()%>/panel.do" id="panelfrm"
                            frameborder="0" allowtransparency="true" hspace="0" vspace="0"
                            scrolling="auto"></iframe>
                </div>
            </div>
        </div>
    </div>
    <!--<div class="foot-panel"><p>中国移动通信集团</p></div>-->
</div>
<div id="personalize"></div>
<div id="shortcutdialog"></div>
<jsp:include page="uedScript.jsp"></jsp:include>
<jsp:include page="messager.jsp"></jsp:include>

<div id="mm" class="easyui-menu" style="width: 100px;">
    <div>
        <a href="#" class="modal_box_iframe"><img width="20px"
                                                  height="18px" src="<%=application.getContextPath()%>/nresources/ued/images/image-5.png" />个性化设置</a>
    </div>
    <div>
        <a href="#" class="person_record"><img width="20px"
                                               height="20px" src="<%=application.getContextPath()%>/nresources/ued/images/image-5.png" />通讯录</a>
    </div>
    <div>
                <span>
				<a href="#" id="msgCenter" class="showMessager"><img width="20px" height="18px"
                                                                     src="<%=application.getContextPath()%>/nresources/ued/images/image-5.png" />消息中心</a>
			    </span>
    </div>
    <div>
                <span>
			    <a href="#" id="onlineServer" class="onlineService"><img width="20px" height="18px"
                                                                         src="<%=application.getContextPath()%>/nresources/ued/images/image-5.png" />在线客服</a>
			    </span>
        <div class="menu-content" style="text-align: left; padding: 10px">
            <div class="online-user">
                <div rel="online-content">
                </div>
            </div>
        </div>
    </div>
    <s:iterator value="currentUser.roles" id="role">
        <s:if test ='%{#role.ROLE_ID == "1050"}'>
            <div>
					<span>
						<a href="#" id="changeUser" class="changeUser"><img width="20px" height="18px"
                                                                            src="<%=application.getContextPath()%>/nresources/ued/images/image-5.png" />切换用户</a>
					</span>
            </div>
        </s:if>
    </s:iterator>
</div>
<p ref='shortcut' class="side-list-2">
			<span><img src="<%=application.getContextPath()%>/nresources/ued/images/icon-b.png" /><a
                    href="#">系统服务热线</a> </span>
</p>
</div>
<div id="short_win" title="快捷菜单设置" style="display:none">
    <div class="form-wrapper">
        <form id="shortcutEditForm" method="post">
            <input type="hidden" name='shortcutForm.module_id' />
            <input type="hidden" name='shortcutForm.login_id' value="<s:property value="currentUser.LOGIN_ID" />" />
            <table class="table-03">
                <tr>
                    <td>
                        分类：
                    </td>
                    <td>
                        <select id="shortcutTypeSelect" name="shortcutForm.type_id" style="width:100px">
                        </select>
                        <!--
                            <a id="shortcut-create" href="javascript:void(0)" >新建</a>
                            <div id="addShortcutType" style="display:none">
                                <input id="shortcutName" type="text" />
                                <input id="saveShortcutType" type="button" class="btn-style02" align="middle" value="保存" />
                            </div>
                         -->
                    </td>
                </tr>
                <tr>
                    <td>
                        快捷名称:
                    </td>
                    <td>
                        <input type="text" name="shortcutForm.shortcut_name" value="" />
                    </td>
                </tr>
                <tr>
                    <td>
                        快捷路径:
                    </td>
                    <td>
                        <input type="text" name="shortcutForm.shortcut_path" value="" readonly/>
                    </td>
                </tr>
            </table>
            <div class="block03">
                <a id="shortcut-submit" href="javascript:void(0)"
                   class="easyui-linkbutton">保存</a>
            </div>
        </form>
    </div>
</div>
<div id="mask" style="display:none" class="mask"></div>
<jsp:include page="uedScript.jsp"></jsp:include>
<jsp:include page="messager.jsp"></jsp:include>
</body>
</html>
<script type="text/javascript">
var tab = null;
var loginId = '<s:property value="currentUser.LOGIN_ID" />';
var messageSetting;
var shortcutMenus;
var clientwidth = 0;
$(function(){
    $(".title-style a.fold-tip").toggle(toggletip,toggletip);
    function toggletip() {
        if ($(".tabspage").attr('class').indexOf("tabspage-2") < 0) {
            $(".tabspage").addClass("tabspage-2");
        } else {
            $(".tabspage").removeClass("tabspage-2");
        }
    }
})
$(document).ready(function(){
	
	$("#shortcut-submit").click(function(){
			var user = $("input[name='shortcutForm.login_id']").val();
			var mId = $("input[name='shortcutForm.module_id']").val();
			
			var shortName = $("input[name='shortcutForm.shortcut_name']").val();
			var shortPath = $("input[name='shortcutForm.shortcut_path']").val();
			
			var $typeObj = $("select[name='shortcutForm.type_id'] option:selected");
			var typeId = $typeObj.val();
			if(typeId==""){
				$('#shortmenuShow').menu('appendItem', {
					text: '<a moduleId="'+mId+'" style="cursor: hand;" path="'+shortPath+'">'+shortName+'</a>',
					iconCls: 'icon-tip',
					onclick:function(){
						var $clickObj = $(this).find("a");
						// 添加快捷菜单单击事件
						var tabId = $clickObj.attr("moduleId");
						$(".tabspage").removeClass("tabspage-2");
				    	tab.addTabItem({tabid : tabId,text: $clickObj.text(), url: $clickObj.attr("path") });
					}
				});
			}else{
				var typeName = $typeObj.text();
				var item = $('#shortmenuShow').menu('findItem', typeName);
				$('#shortmenuShow').menu('appendItem', {
					parent: item.target,  // the parent item element
					text: '<a moduleId="'+mId+'" style="cursor: hand;" path="'+shortPath+'">'+shortName+'</a>',
					iconCls: 'icon-tip',
					onclick:function(){
						var $clickObj = $(this).find("a");
						// 添加快捷菜单单击事件
						var tabId = $clickObj.attr("moduleId");
						$(".tabspage").removeClass("tabspage-2");
				    	tab.addTabItem({tabid : tabId,text: $clickObj.text(), url: $clickObj.attr("path") });
					}
				});
			}
			$("#shortcutEditForm").form('submit',{
	    		url:"<%=application.getContextPath()%>/shorcut/save.do",
	    		data:"shortcutForm.login_id="+user+"&shortcutForm.module_id="+mId+"&shortcutForm.type_id="+typeId+"&shortcutForm.shortcut_name="+shortName+"&shortcutForm.shortcut_path="+shortPath,
	    		success:function(data){
	    			$('#short_win').window('close');
	    			getShortcut();
	    			setShortCutLi();
	    		}
	    	})
		});
	
	/**
    $("#shortcut-submit").click(function(){
        var user = $("input[name='shortcutForm.login_id']").val();
        var mId = $("input[name='shortcutForm.module_id']").val();
        var $typeObj = $("select[name='shortcutForm.type_id'] option:selected");
        var typeId = $typeObj.val();
        if(typeId==""){
            alert("请选择分类");
            return false;
        }
        var typeName = $typeObj.text();
        var shortName = $("input[name='shortcutForm.shortcut_name']").val();
        var shortPath = $("input[name='shortcutForm.shortcut_path']").val();
        var item = $('#shortmenuShow').menu('findItem', typeName);
        $('#shortmenuShow').menu('appendItem', {
            parent: item.target,  // the parent item element
            text: '<a moduleId="'+mId+'" style="cursor: hand;" path="'+shortPath+'">'+shortName+'</a>',
            iconCls: 'icon-tip',
            onclick:function(){
                var $clickObj = $(this).find("a");
                // 添加快捷菜单单击事件
                var tabId = $clickObj.attr("moduleId");
                $(".tabspage").removeClass("tabspage-2");
                tab.addTabItem({tabid : tabId,text: $clickObj.text(), url: $clickObj.attr("path") });
            }
        });
        $("#shortcutEditForm").form('submit',{
            url:"<%=application.getContextPath()%>/shorcut/save.do",
            data:"shortcutForm.login_id="+user+"&shortcutForm.module_id="+mId+"&shortcutForm.type_id="+typeId+"&shortcutForm.shortcut_name="+shortName+"&shortcutForm.shortcut_path="+shortPath,
            success:function(data){
                $('#short_win').window('close');
                getShortcut();
                setShortCutLi();
            }
        })
    });
    */
    //添加快捷菜单
    function addShortMenu(){
        var tabId = tab.getSelectedTabItemID();
        var $tabObj = $("li[tabid='"+tabId+"']");
        tabId = tabId.replace(/___/,'').replace(/sortcut_/,'');
        if(tabId.indexOf('tree')>0)
            tabId = tabId.substring(0,tabId.indexOf('tree'));
        if(tabId!='indexpage'){
            var cfgFlag = false;
            $.each(shortcutMenus,function(idx,item){
                if(item.module_id==tabId){
                    cfgFlag = true;
                }
            });
            if(cfgFlag){
                $.messager.alert('快捷菜单已存在','快捷菜单已添加，不能重复添加！');
                return;
            }
            var src=$tabObj.attr("src");
            var name=$tabObj.attr("name");
            $("input[name='shortcutForm.module_id']").val(tabId);
            $("input[name='shortcutForm.shortcut_name']").val(name);
            $("input[name='shortcutForm.shortcut_path']").val(src);
            $("#short_win").show().window({
                width:300,
                height:200,
                modal:true
            });
        }else{
            $.messager.alert('首页不能设置为快捷方式','首页不能设置为快捷方式！');
        }
    }

    function getSubstr(str,length){
        if(str.length>length)
            return str.substring(0,length);
        else
            return str;
    }
    //快捷菜单滚动控件
    function setShortCutLi(){
        var $shotCutList = $("#shotCutList");
        var $scroolpanel = $(".scroolpanel");
        $scroolpanel.remove();

        $shotCutUl = $('<ul class="end" id="shotCutUl" style="float:left;"></ul>');

        //var $shotCutList = $("#shotCutUl");
        //$("li",$shotCutUl).remove();
        $.each(shortcutMenus,function(idj,shorcutMenu){
            $shotCutUl.append('<li system_id="'+shorcutMenu.module_id+'" style="width:120px" align="center"><div align="center"><a href="#" onclick="showShotTab(this)" module_id='+shorcutMenu.module_id+' shortcut_name='+shorcutMenu.shortcut_name+' shortcut_path='+shorcutMenu.shortcut_path+' title="'+shorcutMenu.shortcut_name+'">'+getSubstr(shorcutMenu.shortcut_name,8)+'</a></div></li>');
        });

        $scroolpanel = $('<div class="scroolpanel"></div>');
        $scroolpanel.append($shotCutUl);
        $shotCutList.append($scroolpanel);

        if(shortcutMenus!=null && shortcutMenus != undefined && shortcutMenus!='')
        {
            clientwidth = $(window).width();
            var w = clientwidth*0.6;
            var num = parseInt(w/120);

            //滚动
            $(".scroolpanel").jCarouselLite({
                btnNext: ".move-right",
                btnPrev: ".move-left",
                circular: false,
                visible: num
            });

            if(shortcutMenus.length<=num){
                $(".move-right").hide();
                $(".move-left").hide();
            }else{
                $(".move-right").show();
                $(".move-left").show();
            }
        }else{
            $(".move-right").hide();
            $(".move-left").hide();
        }
    }

    function getShortcut(){
        $.ajax({
            url:"<%=application.getContextPath()%>/shorcut/queryShortcut.do",
            data:"shortcutForm.login_id="+loginId,
            type:"post",
            async:false,
            success:function(msg){
                shortcutMenus = msg;
            }
        });
    }

    $("#editShortMenu").click(function(){
        window.showModalDialog("<%=application.getContextPath()%>/shorcut/loadShortcutManange.do","","help:no;scroll:no;status:no;dialogHeight:500px;dialogWidth:400px");
        initMenu();
    });

    $("#account").click(function(e){
        // 获取account的位置
        var position = $(this).offset();
        $('#mm').menu('show', {
            left: position.left,
            top: position.top+15
        });
    });

    $("#shortmenuBtn").click(function(){
        var position = $(this).offset();
        $('#shortmenuShow').menu('show', {
            left: position.left,
            top: position.top+15
        });
    });

    // 默认情况让左边菜单栏隐藏
    $(".side-tt .l-layout-header-toggle").click();

    // 加载快捷菜单
    $("div[data-role='accordion']").append($("#sortcutMenu").children().clone());

    // 将首页内容tab隐藏
    $(".tabspage").addClass("tabspage-2");

    tab = $("div.tabspage").uedGetTabManager({
        dblClickToClose: true, //是否双击时关闭
        dragToMove: true,    //是否允许拖动时改变tab项的位置
        contextmenu:true
    });

    $(".right-panel ul li a").click(function(){
        var $clickSystem = $(this);
        var sys_id = $clickSystem.attr('system_id');
        var sys_name = $clickSystem.text();
        var sys_path = $clickSystem.attr('system_path');
        var target = $clickSystem.attr('module_target');

        if(sys_id=='mainpage'){
            tab.selectTabItem('indexpage');
        }
        if(sys_path!=null && sys_path!="null" && sys_path!="" && target!="tab"){
            window.open(sys_path);
            return;
        }
        $clickSystem.parent().parent().find("a[class='on']").removeClass("on");
        $clickSystem.addClass("on");
        var $isExist = $('div[system_id="menu_'+sys_id+'"]');
        if($isExist.text()!=''){
            $isExist.stop(false,true).fadeIn();
            return;
        }
        var $hoverContent = $('<div class="hoverContent" system_id="menu_'+sys_id+'">正在加载...</div>');
        $hoverContent.stop(false,true).fadeIn();
        $('li[system_id="'+sys_id+'"]').append($hoverContent);
        // 加载子节点
        $.getJSON("loadAllNodeLevelByParentId.do?module_id="+ sys_id +"&level=1&date=" + new Date(),
                function(data){
                    var jsonArray = eval(data);
                    $hoverContent.empty();
                    var $f_l = $('<div class="sysMenuCon f_l mgl-10"></div>');
                    var $f_r = $('<div class="sysMenuCon f_r mgr-10"></div>');
                    var idx = 0;
                    $.each(jsonArray, function(i, item){
                        // 包装平铺菜单
                        var userData = item.userData;
                        if(userData.MODULE_LEVEL == 1){
                            var $secdLevel;
                            if(userData.MODULE_PATH!=null && userData.MODULE_PATH!="null" && userData.MODULE_PATH!=""){
                                if(userData.MODULE_TARGET=="blank"){
                                    $secdLevel = $('<div class="bor-t-no title-style03" level="1" module_id="'+item.id+'"><h2><a href="'+userData.MODULE_PATH+'" target="_blank">'+item.name+'</a></h2></div>');
                                }else{
                                    $secdLevel = $('<div class="bor-t-no title-style03" level="1" module_id="'+item.id+'"><h2><a href="#">'+item.name+'</a></h2></div>');
                                    $secdLevel.find('a').bind('click',function(){
                                        $(".right-panel-t .blue-link li").find(".hoverContent").stop(false,true).fadeOut();
                                        var moduleId = item.id;
                                        var tabId = "___" + moduleId;
                                        var tabName = item.name;
                                        var url = userData.MODULE_PATH;
                                        var refresh = userData.is_refresh;
                                        $(".tabspage").removeClass("tabspage-2");
                                        // 添加title
                                        //addCenterTitle(treeNode,treeId);
                                        if(!tab.isTabItemExist(tabId)){
                                            // 添加tab
                                            tab.addTabItem({ tabid : tabId,text: tabName, url: url });
                                            var $newEle = $("li[tabid=" + tabId + "]");
                                            saveLog(tabId);
                                        }else{
                                            tab.selectTabItem(tabId);
                                            // 是否刷新tab
                                            if(refresh=="1"){
                                                tab.reload(tabId);
                                            }
                                        }
                                    });
                                }
                            }else{
                                $secdLevel = $('<div class="bor-t-no title-style03" level="1" module_id="'+item.id+'"><h2>'+item.name+'</h2></div>');
                            }
                            if(idx%2==0){
                                $f_l.append($secdLevel);
                                $hoverContent.append($f_l);
                            }else{
                                $f_r.append($secdLevel);
                                $hoverContent.append($f_r);
                            }
                            idx++;
                        }
                    });

                    $hoverContent.find('div[level="1"]').each(function(){
                        var $parent = $(this);
                        var level1_id = $parent.attr('module_id');
                        $.each(jsonArray, function(i, item){
                            if(level1_id == item.pId){
                                var level2;
                                if(item.userData.MODULE_PATH!=null && item.userData.MODULE_PATH!="null"){
                                    if(item.userData.MODULE_TARGET=="blank"){
                                        level2 = $('<div level="2" module_id="'+item.id+'" module_name="'+item.name+'" module_path="'+item.userData.MODULE_PATH+'" is_refresh="'+item.userData.IS_REFRESH+'"><a href="'+item.userData.MODULE_PATH+'" target="_blank"><strong>'+item.name+'</strong></a></div>');
                                    }
                                    else{
                                        level2 = $('<div level="2" module_id="'+item.id+'" module_name="'+item.name+'" module_path="'+item.userData.MODULE_PATH+'" is_refresh="'+item.userData.IS_REFRESH+'"><a href="#" level="2" module_id="'+item.id+'" module_name="'+item.name+'" module_path="'+item.userData.MODULE_PATH+'" is_refresh="'+item.userData.IS_REFRESH+'"><strong>'+item.name+'</strong></a></div>');
                                        level2.find('a').bind('click',function(){
                                            $(".right-panel-t .blue-link li").find(".hoverContent").stop(false,true).fadeOut();
                                            var moduleId = $(this).attr("module_id");
                                            var tabId = "___" + moduleId;
                                            var tabName = $(this).attr("module_name");
                                            var url = $(this).attr("module_path");
                                            var refresh = $(this).attr("is_refresh");
                                            $(".tabspage").removeClass("tabspage-2");
                                            // 添加title
                                            //addCenterTitle(treeNode,treeId);
                                            if(!tab.isTabItemExist(tabId)){
                                                // 添加tab
                                                tab.addTabItem({ tabid : tabId,text: tabName, url: url });
                                                var $newEle = $("li[tabid=" + tabId + "]");
                                                saveLog(tabId);
                                            }else{
                                                tab.selectTabItem(tabId);
                                                // 是否刷新tab
                                                if(refresh=="1"){
                                                    tab.reload(tabId);
                                                }
                                            }
                                        });
                                    }
                                }else{
                                    level2 = $('<div level="2" module_id="'+item.id+'"><strong>'+item.name+'</strong></div>');
                                }
                                $parent.append(level2);
                            }
                        });
                    });
                    $hoverContent.find('div[level="2"]').each(function(){
                        var $parent = $(this);
                        var level2_id = $parent.attr('module_id');
                        $.each(jsonArray, function(i, item){
                            if(level2_id == item.pId){
                                var level3;
                                if(item.userData.MODULE_PATH!=null && item.userData.MODULE_PATH!="null"){
                                    if(item.userData.MODULE_TARGET=="blank"){
                                        level3 = $('<a href="'+item.userData.MODULE_PATH+'" target="_blank">'+item.name+'</a>');
                                    }
                                    else{
                                        level3 = $('<a  href="#" level="3" module_id="'+item.id+'" module_path="'+item.userData.MODULE_PATH+'" is_refresh="'+item.userData.IS_REFRESH+'">'+item.name+'</a>');
                                        level3.bind('click',function(){
                                            $(".right-panel-t .blue-link li").find(".hoverContent").stop(false,true).fadeOut();
                                            var moduleId = $(this).attr("module_id");
                                            var tabId = "___" + moduleId;
                                            var tabName = $(this).text();
                                            var url = $(this).attr("module_path");
                                            var refresh = $(this).attr("is_refresh");
                                            $(".tabspage").removeClass("tabspage-2");
                                            // 添加title
                                            //addCenterTitle(treeNode,treeId);
                                            if(!tab.isTabItemExist(tabId)){
                                                // 添加tab
                                                tab.addTabItem({ tabid : tabId,text: tabName, url: url });
                                                var $newEle = $("li[tabid=" + tabId + "]");
                                                saveLog(tabId);
                                            }else{
                                                tab.selectTabItem(tabId);
                                                // 是否刷新tab
                                                if(refresh=="1"){
                                                    tab.reload(tabId);
                                                }
                                            }
                                        });
                                    }
                                }else{
                                    level3 = $('<strong>'+item.name+'</strong>');
                                }
                                $parent.append(level3);
                            }
                        });
                    });

                }
        )
    })
            .hover(function(){
                var $onObject = $(this).parent().find('a[class="on"]');
                if($onObject.html()){
                    var $clickSystem = $(this);
                    var sys_id = $clickSystem.attr('system_id');
                    var $isExist = $('div[system_id="menu_'+sys_id+'"]');
                    $isExist.stop(false,true).fadeIn();
                }
            },
            function(){
            }
    );

    $("li[tabid='indexpage']").click(function(){
        //$(".tabspage").addClass("tabspage-2");
    })

    $(".modal_box_iframe").click(function(){
        $("#personalize").dialog({
            title: '个人设置',
            width: 550,
            height: 300,
            closed: false,
            cache: false,
            href: 'loadOldInfoOther.do',
            modal: true
        });
    });

    function initMenu(){
        $("#shortmenuShow").empty();
        $('#shortmenuShow').menu('appendItem', {
            id:'addShortMenu',
            text: '添加',
            iconCls:'icon-add',
            onclick:function(){
                addShortMenu();
            }
        });
        $('#shortmenuShow').menu('appendItem', {
            id:'editShortMenu',
            text: '整理快捷菜单',
            onclick:function(){
                window.showModalDialog("<%=application.getContextPath()%>/shorcut/loadShortcutManange.do","","help:no;scroll:no;status:no;dialogHeight:500px;dialogWidth:400px");
                initMenu();
            }
        });

        // 加载菜单选项
        getShortcut();

        $.ajax({
            url:"<%=application.getContextPath()%>/shorcut/queryShortcutType.do",
            data:"shortcutTypeForm.login_id="+loginId,
            type:"post",
            success:function(msg){
                var $shortmenuShow = $("#shortmenuShow");
                var $shortcutTypeSelect = $("#shortcutTypeSelect");
                $shortcutTypeSelect.empty();
                $shortcutTypeSelect.append("<option value=''>无</option>");
                $.each(msg,function(idx,shortcutType){
                    $shortcutTypeSelect.append("<option value='"+shortcutType.type_id+"'>"+shortcutType.type_name+"</option>");
                    $('#shortmenuShow').menu('appendItem', {
                        id:'type_'+shortcutType.type_id,
                        text: shortcutType.type_name,
                        iconCls: 'icon-mini-edit'
                    });

                });

                $.each(msg,function(idx,shortcutType){
                    var item = $('#shortmenuShow').menu('findItem', shortcutType.type_name);  // find 'Open' item
                    $.each(shortcutMenus,function(idj,shorcutMenu){
                        if(shorcutMenu.type_id==shortcutType.type_id){
                            $('#shortmenuShow').menu('appendItem', {
                                parent: item.target,  // the parent item element
                                text: '<a moduleId="'+shorcutMenu.module_id+'" style="cursor: hand;" path="'+shorcutMenu.shortcut_path+'">'+shorcutMenu.shortcut_name+'</a>',
                                iconCls: 'icon-tip',
                                onclick:function(){
                                    var $clickObj = $(this).find("a");
                                    // 添加快捷菜单单击事件
                                    var tabId = "sortcut_"+$clickObj.attr("moduleId");
                                    $(".tabspage").removeClass("tabspage-2");
                                    tab.addTabItem({tabid : tabId,text: "快捷:"+$clickObj.text(), url: $clickObj.attr("path") });
                                    saveLog(tabId);
                                }
                            });
                        }
                    });
                });
                setShortCutLi();
            }
        });
        $('#shortmenuShow').menu('hide');
    }
    /*消息中心主要查看系统或个人的消息*/
    var initMsg = function(){
        $.ajax({
            url:"loadOnlineMsgUser.do?loginId="+loginId,
            type:"post",
            async:false,
            success:function(data){
                data = eval(data);
                var $select = $("#centerUsers");
                $select.children().remove();
                $.each(data,function(idx , ele){
                    $select.append("<option value='"+ele.LOGIN_ID+"'>"+ele.NAME+"</option>");
                });
                //alert("init center over");
                //$("#msgCenterShow").append($msgSenderUser);
            }
        });
        var onlineServerUser = [{loginId:"admin",userName:"管理员1"},{loginId:"admin",userName:"管理员2"},{loginId:"other",userName:"其他"}];
        var $msgSenderUser = $(".online-user");
        var $select = $msgSenderUser.find("div[rel='online-content']");
        // 获取和admin用户交互过的用户信息
        $.each(onlineServerUser,function(idx,ele){
            var $userObj = $("<div style='display:inline-block;cursor:hand;margin-right:5px' rel='"+ele.loginId+"'><div><img src='<%=application.getContextPath()%>/nresources/ued/images/image-4.png' style='width:30px;height:30px' /></div><div>"+ele.userName+"</div></div>");
            $select.append($userObj);
            $userObj.unbind().bind('click',function(){
                var receiver = ele.loginId;
                if(receiver=='other'){
                    var selectUser = window.showModalDialog('<%=application.getContextPath()%>/loadUserManage.do?type=select','选择用户','help:no;scroll:no;status:no;dialogHeight:600px;dialogWidth:900px');
                    if(selectUser!=undefined){
                        var name = "";
                        receiver = selectUser[0].LOGIN_ID;
                        name = selectUser[0].NAME;
                        onLineMsgShow(loginId,receiver);
                    }
                }else{
                    onLineMsgShow(loginId,receiver);
                }
            });
        });
        initMenu();
    }()

})


// 加载消息设置
$.ajax({
    url:"queryMessageSetting.do",
    type:"post",
    success:function(data){
        messageSetting = data;
    }
});

$(".icon-tip").hover(function(){
    alert('');
})

//保存模块访问日志
function saveLog(moduleId){
    var flag = "sortcut_";
    if(moduleId.indexOf(flag)>=0){
        moduleId = moduleId.substring(moduleId.indexOf(flag)+flag.length);
    }


    flag = "___";
    if(moduleId.indexOf(flag)>=0){
        moduleId = moduleId.substring(moduleId.indexOf(flag)+flag.length);
    }

    $.ajax({
        url:"saveModuleLog.do?moduleId="+moduleId,
        type:"post",
        success:function(data){
        }
    });
}

//加载树 isExpandFirstNode为true展开第一个数 false不展开
function loadRootNode($treeObj,rootId){
    $treeObj.html("loading...");
    // 异步加载节点信息，将全部节点信息一次性加载到页面
    $.ajax({
        url:"loadSubNodeByModuleId.do?id="+rootId,
        type:"POST",
        success : function(msg){
            $treeObj.html("");
            msg = eval(msg);
            $.fn.zTree.init($treeObj, {
                treeId:"id",
                data: {
                    key:{
                        name:'name',
                        title:'name',
                        id:'id'
                    },
                    simpleData:{
                        idKey:'id'
                    }
                },
                async:{
                    enable:true,
                    type:"post",
                    dataType:"json",
                    autoParam:["id"],
                    url:"loadSubNodeByModuleId.do",
                    dataFilter:function(treeId, parentNode, responseData){
                        return eval(responseData);
                    }
                },
                view: {
                    fontCss: function (treeId, treeNode) {
                        return (!!treeNode.highlight) ? {color:"#A60000", "font-weight":"bold"} : {color:"#333", "font-weight":"normal"};
                    },
                    dblClickExpand:true
                },
                callback:{
                    onClick : function(event, treeId, treeNode){
                        //alert(treeNode.tId);
                        var tabId = rootId + "___" + treeNode.tId;
                        // 添加title
                        //addCenterTitle(treeNode,treeId);
                        if(!tab.isTabItemExist(tabId)){
                            // 添加tab
                            tab.addTabItem({ tabid : tabId,text: treeNode.name, url: treeNode.userData.PATH });
                            var $newEle = $("li[tabid=" + tabId + "]");
                            $newEle.click(function(){
                                var tabIdSplits = $(this).attr("tabid").split("___");
                                var seleTreeId = "tree_"+tabIdSplits[0];
                                var seleNodeId = tabIdSplits[1];
                                invertTreeNode(seleTreeId,seleNodeId,false);
                            });
                        }else{
                            tab.selectTabItem(tabId);
                            // 是否刷新tab
                            if(treeNode.userData.IS_REFRESH=="1"){
                                tab.reload(tabId);
                            }
                        }
                    },
                    onNodeCreated:function(event, treeId, treeNode){

                    }
                }
            }, msg);
        }
    });
}

// 反选树节点
function invertTreeNode(treeId,treeNodeId,hasTab){
    // 判断accordion是否被选中
    $(".l-accordion-toggle-close").removeClass('l-accordion-toggle-close').addClass("l-accordion-toggle-open");
    $(".l-accordion-toggle[module_id='"+treeId.replace(/tree_/g,'')+"']").addClass("l-accordion-toggle-close").click();
    //alert($(".l-accordion-toggle").find("div[module_id='"+treeId.replace(/tree_/g,'')+"']"));
    // 对树节点操作
    // 首先要选中accordion,然后再对下面的数节点进行操作
    var treeObj = $.fn.zTree.getZTreeObj(treeId);
    var treeNodes = treeObj.getNodes();
    var matchObj = treeObj.getNodeByTId(treeNodeId);
    treeObj.selectNode(matchObj,false);
}

// 从树中查找到与
function findMatchTreeNodeByTreeNodeId(treeNode,treeIdx){
    var matchObj;
    if(treeNode.tId==treeIdx){
        return treeNode;
    }else{
        if(treeNode.isParent && treeNode.children){
            var childNodes = treeNode.children;
            for(var idx = 0 ; idx < childNodes.length ; idx ++){
                matchObj = findMatchTreeNodeByTreeNodeId(childNodes[idx],treeIdx);
                if(matchObj!=null){
                    break;
                }
            }
        }
    }
    return matchObj;
}

$(document).ready(function(){
    $(".showMessager").click(function(){
        tabId = "showMessager";
        tabName = "历史消息";
        url = "loadMsgHisList.do";

        addTab(tabId,tabName,url);

    });
    loadUnreadMsg('auto');

    $(".changeUser").click(function(){
        var selectUser = window.showModalDialog('<%=application.getContextPath()%>/loadUserManage.do?type=select','选择用户','help:no;scroll:no;status:no;dialogHeight:600px;dialogWidth:900px');
        if(selectUser!=undefined){
            var id = "";
            var name = "";
            for (var one in selectUser){
                id = id + selectUser[one].LOGIN_ID + ",";
            }
            if(id.length>0){
                id = id.substring(0,id.length-1);
            }
            window.location.href = "logout.do?changeUserId="+id;
            <%--$.ajax({--%>
                <%--url:"<%=application.getContextPath()%>/logoutForChangeUser.do",--%>
                <%--type:"post",--%>
                <%--async:false,--%>
                <%--success:function(msg){--%>
                    <%--for (var one in msg){--%>
                        <%--var PARA_ID = msg[one].PARA_ID;--%>
                        <%--var url = msg[one].PARA_VALUE;--%>

                        <%--if (PARA_ID != "FINAL_LOGOUT") {--%>
                            <%--var iframe = document.createElement("iframe");--%>
                            <%--iframe.src = url;--%>
                            <%--iframe.style.display = "none";--%>
                            <%--document.body.appendChild(iframe);--%>
                        <%--}--%>
                    <%--}--%>
                    <%--$.ajax({--%>
                        <%--url:"<%=application.getContextPath()%>/changeUser.do",--%>
                        <%--data:"loginId="+id,--%>
                        <%--type:"post",--%>
                        <%--async:false,--%>
                        <%--success:function(msg){--%>
                            <%--window.location.reload();--%>
                        <%--}--%>
                    <%--});--%>
                <%--}--%>
            <%--});--%>
        }
    });

    //layout resize后，设置高度
    $(window).bind("afterResizeLayout",function(){
        setLayHeight();
        return false;
    });

    setLayHeight();

})

function showShotTab(menu){
    //alert(($(menu)).attr('shortcut_path'));
    var $menu = $(menu);
    var id = $menu.attr('module_id');
    var name = $menu.attr('shortcut_name');
    var path = $menu.attr('shortcut_path');
    addTab(id,name,path);
    saveLog(id);
}


//打开tab，带sysId，用于树定位
function addSysTab(tabId,tabName,url,sysId){
    if(!tab.isTabItemExist(tabId)){
        // 添加tab
        $(".tabspage").removeClass("tabspage-2");
        setLayHeight();
        tab.addTabItem({ tabid : tabId,text: tabName, url: url ,sysid: sysId});
    }else{
        tab.selectTabItem(tabId);
        tab.reloadUrl(tabId,url);
    }
}

//设置.l-tab-content高度，否则会出现tab消失的情况
function setLayHeight(){
    var h1 = $(".l-tab-content").height();
    var h2 = $(".l-tab-links").height();
    $(".l-tab-content").height(h1-h2);
}

//提供给外部系统的方法 start
function addTab(tabId,tabName,url){
    if(!tab.isTabItemExist(tabId)){
        // 添加tab
        $(".tabspage").removeClass("tabspage-2");
        setLayHeight();
        tab.addTabItem({ tabid : tabId,text: tabName, url: url });
    }else{
        tab.selectTabItem(tabId);
        tab.reloadUrl(tabId,url);
    }
}
function removeTab(tabId){
    if(tab.isTabItemExist(tabId)){
        tab.removeTabItem(tabId);
    }
}

function refreshPanel(panelId){
    var $iframe = $("#panelfrm").contents().find("#"+panelId+" iframe");
    $iframe.attr("src",$iframe.attr("src"));
}

function autoHeight(panelId,iframe_height){
    if(iframe_height!="0"){
        var $newbox = $("#panelfrm").contents().find("#"+panelId);
        var $ttcorner = $(".newbox-tt",$newbox);
        var $newboxArea = $(".newbox-area",$newbox);

        var ttHeight = $ttcorner.height();
        var h = parseInt(iframe_height) + parseInt(ttHeight);
        $newbox.attr({style:"height:"+h+"px"});
        $newboxArea.attr({style:"height:"+iframe_height+"px"});
    }
}
//提供给外部系统的方法 end
</script>

